package com.tianxinweb.interceptors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by cboy on 2018/3/15.
 * 继承WebMvcConfigurationSupport可以实现拦截静态资源
 */
@Configuration
public class InteceptorRegistry implements WebMvcConfigurer {

    @Autowired
    private PrivilegeInterceptor privilegeInterceptor;
    @Autowired
    private LoginCheckInteceptor loginCheckInteceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(loginCheckInteceptor).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/logout");
        registry.addInterceptor(privilegeInterceptor).addPathPatterns("/**").excludePathPatterns("/admin/login", "/admin/logout");
    }
}
